#define _CRT_SECURE_NO_WARNINGS 1
#include<map>
#include<string>
#include<iostream>

using namespace std;

int minNumberOfFrogs(string croakOfFrogs) {
    map<char, int> hash;
    string c{ "croak" };
    for (auto ch : c)
        hash[ch] = 0;
    map<char, char> front;
    for (int i = 0; i < c.size(); ++i)
        front[c[i]] = c[(i + c.size() - 1) % c.size()];
    for (auto ch : croakOfFrogs) {
        if (!hash.count(ch))
            return -1;
        else if (ch == c[0]) {
            if (hash[front[ch]] > 0) {
                --hash[front[ch]];
                ++hash[ch];
            }
            else
                ++hash[ch];
        }
        else {
            if (hash[front[ch]] == 0)
                return -1;
            --hash[front[ch]];
            ++hash[ch];
        }
    }

    for (auto ch : c) {
        if (ch != c[c.size() - 1] && hash[ch] != 0)
            return -1;
    }
    return hash[c[c.size() - 1]];
}

int main()
{
    int ret = minNumberOfFrogs("crcoakroak");
    cout << ret;
    return 0;
}